package com.sfx.concurrent.demo.concurrent.concurrentHashMap;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-03-04
 * Time: 20:33
 */
public class hashMapConcurrentIssue {


    public static void main(String[] args) throws InterruptedException {
        ConcurrentHashMap<String,Integer> concurrentHashMap
                = new ConcurrentHashMap<>();
        concurrentHashMap.put("1",10);
        HashMap<String,Object> map = new HashMap<>();
        Thread t1 = new Thread(() -> {
            map.put("a",new Object());
        },"t1");

        Thread t2 = new Thread(() -> {
            map.put("b", new Object());
        }, "t2");

        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(map);
    }

}
